package client.comm.commlib.widget

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager

class PreviewerViewPager @JvmOverloads constructor(context: Context?, attrs: AttributeSet? = null) :
    ViewPager(
        context!!, attrs
    ) {
    private var isInterceptable = false
    private var isTransition = false
    private var mScrollState = SCROLL_STATE_IDLE
    override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
        return try {
            super.onInterceptTouchEvent(ev)
        } catch (e: IllegalArgumentException) {
            false
        }
    }

    fun isInterceptable(b: Boolean) {
        if (!isInterceptable && b) isTransition = true
        isInterceptable = b
    }

    private inner class PageChangeListener : SimpleOnPageChangeListener() {
        override fun onPageScrollStateChanged(state: Int) {
            mScrollState = state
        }
    }

    init {
        addOnPageChangeListener(PageChangeListener())
    }
}